package com.unknown.network;

import android.support.annotation.NonNull;

import com.unknown.common.function.SEFunction;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class NetworkCallback<T> implements Callback<T> {
    private SEFunction<T> onSuccessListener;
    private SEFunction<Throwable> onFailureListener;

    public NetworkCallback(SEFunction<T> onSuccessListener, SEFunction<Throwable> onFailureListener) {
        this.onSuccessListener = onSuccessListener;
        this.onFailureListener = onFailureListener;
    }

    @Override
    public void onResponse(@NonNull Call<T> call, @NonNull Response<T> response) {
        onSuccessListener.apply(response.body());
    }

    @Override
    public void onFailure(@NonNull Call<T> call, @NonNull Throwable t) {
        onFailureListener.apply(t);
    }
}
